PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Relative

The Relative reference form specifies an object or a location by describing its position in relation to another object, known as the base, in the same container.

SYNTAX
[ className ] ( before | [in] front of ) baseReference [ className ] ( after | [in] back of | behind ) baseReference

where

className is the class identifier of the specified object. If you leave out this parameter, AppleScript assumes you want an insertion point.

baseReference is a reference to the base object.

The before and in front of forms, which are equivalent, refer to the object immediately preceding the base object. The after, in back of, and behind forms are equivalent and refer to the object immediately after the base.

The following forms refer to insertion points:

beginning | front end | back

The beginning and front forms are equivalent and refer to the first insertion point of the container ( insertion point 1 ). The end and back forms are equivalent and refer to the last insertion point of the container ( insertion point -1 ).

Although terms such as beginning and end sound like absolute positions, they are relative to the existing contents of a container (that is, before or after the existing contents).

EXAMPLES

The two references in the following Tell block specify the same file by identifying its position relative to another file on a disk.

tell application "Finder"
    file before file 3 of startup disk
    file in front of file 3 of startup disk
end tell

The following example contains three references. The first two are Index references that specify the front document and the first word. The third is a Relative reference that specifies the insertion point before the third paragraph. The command moves the first word to the insertion point before the third paragraph.

tell front document of application "AppleWorks"
    move word 1 of text body to before paragraph 3 of text body
end tell

The following example moves the first word of a document named Introduction to the last insertion point of the document, then moves the last word of the document to the first insertion point (effectively undoing the previous move).

tell application "AppleWorks"
    move word 1 of text body of document "Introduction" ¬
        to end of text body of document "Introduction"
    move last word of text body of document "Introduction" ¬
        to beginning of text body of document "Introduction"
end tell

The following example is the same as the previous example, except that it uses in front and in back instead of beginning and end.

tell application "AppleWorks"
    move word 1 of text body of document "Introduction" ¬
        to in back of text body of document "Introduction"
    move last word of text body of document "Introduction" ¬
        to in front of text body of document "Introduction"
end tell
NOTES

You can specify only a single object with the Relative form. You can use the form to specify an object that is either before or after the base object.

If it is possible for the specified object to contain the base object (as in the expression paragraph before word 99 ), the reference does not specify the container but instead specifies the object immediately before or after the container of the base object. For example, the expression paragraph before word 99 specifies the paragraph immediately before the paragraph containing the ninety-ninth word.

All applications allow you to specify a base object belonging to the same class as the desired object (such as window in back of window "Big" ). Not all allow you to specify a base of a different object class (such as word before figure 1 ). The possible base classes for a particular class are up to each application.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)